public class Test05 {
    public static void main(String[] args) {
        double[] arr = {1,2,3,4,5};

        double avg=getAvg(arr);
        System.out.println(avg);    
            }
     public static  double getAvg(double[] arr){
        double avg=0;
        double sum=0;
        //遍历数组，求和
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        //元素和除以数组长度
        int num=arr.length;
        avg=sum/num;
        return avg;
    }
}
